**********************************************
**** Table A10: Heterogeneity by Wealth, Financial Constraints, and Demographics
**********************************************


use "$dir/Data/analysis_main.dta", clear
keep if survsample==1

gen anychildren_miss = children_miss
gen wealth_hi_avg_miss = 0

	eststo clear
	
	foreach x of varlist richhouse ownland hasnocredits canget1k {
		
		cap drop *_hiw
		foreach y of varlist cash_postpay {
			gen `y'_hiw = `x'_m*`y'
		}		

		eststo: reghdfe n_productivity cash_postpay cash_announce cash_postpay_hiw `x'_m blhrprod blhrprodsq blhrprod_miss bs_labor_30_miss future_fin_worry_miss i.pd if pd>0 & survsample==1, vce(cl pid) absorb(roundgroup)
		qui lincom cash_postpay + cash_postpay_hiw
		qui estadd scalar coef1 = r(estimate)
		qui estadd scalar se1 = r(se)					
		qui estadd scalar pval1 = 2*ttail(r(df),abs(r(estimate)/r(se)))

	}


	foreach x of varlist read_odiya educ age children anychildren {
		
		cap drop *_hiw
		foreach y of varlist cash_postpay {
			gen `y'_hiw = `x'*`y'
		}		

		eststo: reghdfe n_productivity cash_postpay cash_announce cash_postpay_hiw `x' blhrprod blhrprodsq blhrprod_miss bs_labor_30_miss future_fin_worry_miss i.pd if pd>0 & survsample==1, vce(cl pid) absorb(roundgroup)
		qui lincom cash_postpay + cash_postpay_hiw
		qui estadd scalar coef1 = r(estimate)
		qui estadd scalar se1 = r(se)					
		qui estadd scalar pval1 = 2*ttail(r(df),abs(r(estimate)/r(se)))

	}
	
label var cash_postpay "Cash $\times$ Post-pay"
label var cash_postpay_hiw "Cash $\times$ Post-pay" 

#delimit ;
local tablerow cash_postpay cash_postpay_hiw;

esttab using "$oa/$t/Table_A10.tex", 
    b(3) se booktabs star(* .1 ** .05 *** .01) nonotes nomtitles 
    replace label style(tex) gaps keep(`tablerow') order(`tablerow') 
    stats(coef1 empt se1 empt pval1 empt N, labels("Coef: cash effect +" "\hspace{2.6em} interaction" "SE: cash effect +" "\hspace{2.6em} interaction" "P-val: cash effect +" "\hspace{2.6em} interaction" "N: worker-hours") fmt(%9.3fc %9.3fc %9.3fc %9.3fc %9.3fc %9.3fc %9.0fc))    
	prehead("{\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi} 
	\begin{tabular}     
	{@{\extracolsep{4pt}}l*{12}{>{\centering\arraybackslash}m{2cm}}@{}}      \toprule    
	&\multicolumn{2}{c}{\textbf{Wealth}}   &\multicolumn{2}{c}{\textbf{Financial Constraints}} &\multicolumn{5}{c}{\textbf{Demographics}}  \bigstrut       \\ 
	\cline{2-3} \cline{4-5}  \cline{6-10} \addlinespace 
	& Durable house  & Owns land   & No food loans  & Can access emergency cash & Literacy & Education years & Age & Number of children & Any children   \\
	") ;
		
#delimit cr		


